]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/a11y: Simplify switch setup
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 16 Dec 2024 13:33:00 +0000 (14:33 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 10 Jan 2025 11:46:56 +0000 (12:46 +0100)
Almost all switches represent boolean settings, which means we can
use bindings instead of fiddling with signal handlers.

As menu items have a `:sensitive` property, this also deals with
handling keys' writability.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3576>
(cherry picked from commit 6029380267879eb6491a9f429afa22b380da4fa2)

js/ui/status/accessibility.js

index b36c648682bbc17e8e21df75aa0e077a1f3e14e5..5e6c447f33737e6fd545fe4c240256bf2a5361d3 100644 (file)
@@ -118,17 +118,12 @@ class ATIndicator extends PanelMenu.Button {
     }
 
     _buildItem(string, schema, key) {
-        let settings = new Gio.Settings({schema_id: schema});
-        let widget = this._buildItemExtended(string,
-            settings.get_boolean(key),
-            settings.is_writable(key),
-            enabled => settings.set_boolean(key, enabled));
+        const settings = new Gio.Settings({schema_id: schema});
+        const widget = new PopupMenu.PopupSwitchMenuItem(string, false);
+        settings.bind(key, widget, 'state', Gio.SettingsBindFlags.DEFAULT);
 
-        settings.connect(`changed::${key}`, () => {
-            widget.setToggleState(settings.get_boolean(key));
-
-            this._queueSyncMenuVisibility();
-        });
+        widget.connect('toggled',
+            () => this._queueSyncMenuVisibility());
 
         return widget;
     }